package com.controller;

import com.comm.IPAnno;
import com.model.MyIp;
import com.model.eCharts;
import com.service.MyipService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import sun.misc.Request;

import java.util.Date;
import java.util.List;

@Api("我的用户")
@RestController
@RequestMapping("/myIp")
public class MyIpController {

    @Autowired
    private MyipService myipService;

    @CrossOrigin
    @IPAnno(OperateType = "自定义接口")
    @RequestMapping(value = "/addIp",method = RequestMethod.PUT)
    public int addIp(@RequestBody MyIp myIp){
        System.out.println("添加Ip");
        return myipService.addMyIp(myIp);
    }

    @CrossOrigin
    @RequestMapping(value = "/updateIp",method = RequestMethod.PUT)
    public int updateIp(@RequestBody MyIp myIp){
        System.out.println("更新ip");
        return myipService.updateMyIp(myIp);
    }

    @CrossOrigin
    @RequestMapping(value = "/deleteIp",method = RequestMethod.GET)
    public int deleteIp(int userid){
        System.out.println("删除ip");
        return myipService.deleteMyIp(userid);
    }

    @CrossOrigin
    @RequestMapping(value = "/getIpByUserId",produces = "application/json;charset=utf-8",method = RequestMethod.GET)
    public MyIp getIpByUserid(int userid){
        System.out.println("根据id查询ip");
        return myipService.getMyIpByUserid(userid);
    }

    @CrossOrigin
    @RequestMapping(value = "/getIpByTime",produces = "application/json;charset=utf-8",method = RequestMethod.PUT)
    public List<MyIp> getIpByTime( Date data1, Date data2){
        System.out.println("根据时间区域查询ip");
        return myipService.getMyIpByTime(data1,data2);
    }

    @CrossOrigin
    @ApiOperation(value = "获取分析信息")
    @RequestMapping(value = "/getWeekInfo" ,produces = "application/json;charset=utf-8",method = RequestMethod.PUT)
    public List<eCharts> getWeekInfo(MyIp myIp){
        System.out.println("进入分析方法");
        return myipService.weekInfo(myIp);
    }

    @CrossOrigin
    @ApiOperation(value = "获取分析信息")
    @RequestMapping(value = "/getRankInfo" ,produces = "application/json;charset=utf-8",method = RequestMethod.PUT)
    public List<MyIp> getRankInfo(MyIp myIp){
        System.out.println("进入分析方法");
        return myipService.rankInfo(myIp);
    }
}


